package me.jiatao.wan.data.network

/**
 * @Author: taojia
 * @CreateDate: 2021/8/24 5:23 下午
 * @Version: 1.0
 * @Description: http访问响应状态包装类，根据当前状态处理UI显示
 */

sealed class HttpStatusResult<out T> {
    data class Success<out T>(val value: T) : HttpStatusResult<T>()

    data class Failure(val apiException: ApiException) : HttpStatusResult<Nothing>()
}

inline fun <reified T> HttpStatusResult<T>.doSuccess(success: (T) -> Unit) {
    if (this is HttpStatusResult.Success) {
        success(value)
    }
}

inline fun <reified T> HttpStatusResult<T>.doFailure(failure: (apiException: ApiException) -> Unit) {
    if (this is HttpStatusResult.Failure) {
        failure(apiException)
    }
}
